<?php

namespace app\admin\model;

use think\Model;


class OrderProcHelp extends Model
{

    

    

    // 表名
    protected $name = 'order_proc_help';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        "image_url_list"
    ];
    

    //将image_url转换为完整的图片地址
    public function getImageUrlAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image_url']) ? $data['image_url'] : '');
        return cdnurl($value, true);
    }

    //追加一个属性image_url_list,将image_url用,分割转换为image_url_list
    public function getImageUrlListAttr($value, $data)
    {
        $image_url_list = [];
        if ($data['image_url']) {
            $image_url_list = explode(",", $data['image_url']);
            //将$image_url_list遍历,补全图片地址
            foreach ($image_url_list as $key => $value) {
                $image_url_list[$key] = cdnurl($value, true);
            }
        }
        return $image_url_list;
    }




    public function category()
    {
        return $this->belongsTo('Category', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
